// 关键词搜索model
class PageListModel {
  int code;
  String msg;
  PageDataModel? data;

  PageListModel({
    required this.code,
    required this.msg,
    this.data,
  });

  factory PageListModel.fromJson(Map<String, dynamic> json) {
    return PageListModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null ? PageDataModel.fromJson(json['data']) : null,
    );
  }
}

class PageDataModel {
  List<PageDataListModel> list;

  PageDataModel({required this.list});

  factory PageDataModel.fromJson(Map<String, dynamic> json) {
    return PageDataModel(
      list: (json['list'] as List?)?.map((e) => PageDataListModel.fromJson(e)).toList() ?? [],
    );
  }
}

class PageDataListModel {
  int spuId;
  int categoryId;
  String name;
  String pic;

  PageDataListModel({required this.spuId, required this.categoryId, required this.name, required this.pic});

  factory PageDataListModel.fromJson(Map<String, dynamic> json) {
    return PageDataListModel(
      spuId: json['spuId'] ?? 0,
      name: json['name'] ?? '',
      pic: json['pic'] ?? '',
      categoryId: json['categoryId'] ?? 0,
    );
  }
}

// 搜索详情model
class SearchDetailModel {
  int code;
  String msg;
  RechargeTypeModel? data;

  SearchDetailModel({
    required this.code,
    required this.msg,
    this.data,
  });

  factory SearchDetailModel.fromJson(Map<String, dynamic> json) {
    return SearchDetailModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null ? RechargeTypeModel.fromJson(json['data']) : null,
    );
  }
}

class RechargeTypeModel {
  List<TypeListModel> rechargeTypeList;
  String blurb;
  String name;
  String pic;
  String detail;
  String categoryId;
  int sellOut;
  String categoryName;
  // CommentInfoModel? commentInfo;

  RechargeTypeModel({
    required this.rechargeTypeList,
    required this.blurb,
    required this.name,
    required this.pic,
    required this.detail,
    required this.categoryId,
    required this.sellOut,
    required this.categoryName,
  });

  factory RechargeTypeModel.fromJson(Map<String, dynamic> json) {
    return RechargeTypeModel(
      rechargeTypeList: (json['rechargeTypeList'] as List?)?.map((e) => TypeListModel.fromJson(e)).toList() ?? [],
      blurb: json['blurb'] ?? '',
      name: json['name'] ?? '',
      pic: json['pic'] ?? '',
      detail: json['detail'] ?? '',
      categoryId: json['categoryId'] ?? '',
      sellOut: json['sellOut'] ?? 0,
      categoryName: json['categoryName'] ?? '',
    );
  }
}

class TypeListModel {
  List<ReListModel> spuList;
  String name;
  int select;

  TypeListModel({
    required this.spuList,
    required this.name,
    required this.select,
  });

  factory TypeListModel.fromJson(Map<String, dynamic> json) {
    return TypeListModel(
      spuList: (json['spuList'] as List?)?.map((e) => ReListModel.fromJson(e)).toList() ?? [],
      name: json['name'] ?? '',
      select: json['select'] ?? 0,
    );
  }
}

class ReListModel {
  int attrId;
  int spuId;
  String attrvalue;
  String marketPrice;
  String name;
  String pic;
  String priceFee;
  String symbol;
  String tag;
  int? select;

  ReListModel({
    required this.attrId,
    required this.spuId,
    required this.attrvalue,
    required this.marketPrice,
    required this.name,
    required this.pic,
    required this.priceFee,
    required this.symbol,
    required this.tag,
    this.select,
  });

  factory ReListModel.fromJson(Map<String, dynamic> json) {
    return ReListModel(
      attrId: json['attrId'] ?? 0,
      spuId: json['spuId'] ?? 0,
      attrvalue: json['attrvalue'] ?? '',
      marketPrice: json['marketPrice'] ?? '',
      name: json['name'] ?? '',
      pic: json['pic'] ?? '',
      priceFee: json['priceFee'] ?? '',
      symbol: json['symbol'] ?? '',
      tag: json['tag'] ?? '',
      select: json['select'],
    );
  }
}

class CommentListModel {
  double score;
  String msg;
  String name;

  CommentListModel({
    required this.score,
    required this.msg,
    required this.name,
  });

  factory CommentListModel.fromJson(Map<String, dynamic> json) {
    return CommentListModel(
      score: (json['score'] ?? 0).toDouble(),
      msg: json['msg'] ?? '',
      name: json['name'] ?? '',
    );
  }
}

class CommentPageModel {
  int code;
  String msg;
  CommentArrayModel? data;

  CommentPageModel({
    required this.code,
    required this.msg,
    this.data,
  });

  factory CommentPageModel.fromJson(Map<String, dynamic> json) {
    return CommentPageModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null ? CommentArrayModel.fromJson(json['data']) : null,
    );
  }

}

class CommentArrayModel {
  CommentRecordsModel? page;
  String score;

  CommentArrayModel({required this.page,required this.score});

  factory CommentArrayModel.fromJson(Map<String, dynamic> json) {
    return CommentArrayModel(
      page: json['page'] != null ? CommentRecordsModel.fromJson(json['page']) : null,
      score: json['score'] ?? '5.0',
    );
  }
}

class CommentRecordsModel {
  List<CommentListModel> records;

  CommentRecordsModel({required this.records});

  factory CommentRecordsModel.fromJson(Map<String, dynamic> json) {
    return CommentRecordsModel(
      records: (json['records'] as List?)?.map((e) => CommentListModel.fromJson(e)).toList() ?? [],
    );
  }
}



class PageSerachNoModel {
  int code;
  String msg;
  PageDataNoModel? data;

  PageSerachNoModel({
    required this.code,
    required this.msg,
    this.data,
  });

  factory PageSerachNoModel.fromJson(Map<String, dynamic> json) {
    return PageSerachNoModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null ? PageDataNoModel.fromJson(json['data']) : null,
    );
  }
}

class PageDataNoModel {
  List<PageDataListNoModel> h5;

  PageDataNoModel({
    required this.h5,
  });

  factory PageDataNoModel.fromJson(Map<String, dynamic> json) {
    return PageDataNoModel(
      h5: (json['h5'] as List?)?.map((e) => PageDataListNoModel.fromJson(e)).toList() ?? [],
    );
  }
}

class PageDataListNoModel {
  int id;
  String name;
  String pic;

  PageDataListNoModel({
    required this.id,
    required this.name,
    required this.pic,
  });

  factory PageDataListNoModel.fromJson(Map<String, dynamic> json) {
    // 处理id的动态类型
    int id;
    if (json['id'] is int) {
      id = json['id'];
    } else if (json['id'] is String) {
      id = int.tryParse(json['id']) ?? 0;
    } else {
      id = 0;
    }

    return PageDataListNoModel(
      id: id,
      name: json['name'] ?? '',
      pic: json['pic'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'pic': pic,
    };
  }
}




